package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhCouponLog;
import com.ruoyi.edh.service.IEdhCouponLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-优惠券记录Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/coupons")
@Api(description = "易订货-优惠券记录")
public class EdhCouponLogController extends BaseController {
    @Autowired
    private IEdhCouponLogService edhCouponLogService;

    /**
     * 查询易订货-优惠券记录列表
     */
    @GetMapping("/list")
    @ApiOperation("易订货-优惠券记录列表")
    public TableDataInfo list(EdhCouponLog edhCouponLog) {
        startPage();
        List<EdhCouponLog> list = edhCouponLogService.selectEdhCouponLogList(edhCouponLog);
        return getDataTable(list);
    }

    /**
     * 我得优惠券列表
     */
    @GetMapping("/myCouponList")
    @ApiOperation("我得优惠券列表")
    public AjaxResult myCouponList() {
        return AjaxResult.success(edhCouponLogService.myCouponList());
    }

    /**
     * 导出易订货-优惠券记录列表
     */
    @Log(title = "易订货-优惠券记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-优惠券记录列表")
    public AjaxResult export(EdhCouponLog edhCouponLog) {
        List<EdhCouponLog> list = edhCouponLogService.selectEdhCouponLogList(edhCouponLog);
        ExcelUtil<EdhCouponLog> util = new ExcelUtil<EdhCouponLog>(EdhCouponLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取易订货-优惠券记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping
    @ApiOperation("获取易订货-优惠券记录详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhCouponLogService.selectEdhCouponLogById(id));
    }

    /**
     * 领取优惠券
     */
    @Log(title = "易订货-优惠券记录", businessType = BusinessType.INSERT)
    @GetMapping("/getCoupon")
    @ApiOperation("领取优惠券")
    public AjaxResult add(Long couponId) {
        EdhCouponLog edhCouponLog = new EdhCouponLog();
        edhCouponLog.setCouponId(couponId);
        return toAjax(edhCouponLogService.insertEdhCouponLog(edhCouponLog));
    }

    /**
     * 修改易订货-优惠券记录
     */
    @Log(title = "易订货-优惠券记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-优惠券记录")
    public AjaxResult edit(@RequestBody EdhCouponLog edhCouponLog) {
        return toAjax(edhCouponLogService.updateEdhCouponLog(edhCouponLog));
    }

    /**
     * 删除易订货-优惠券记录
     */
    @Log(title = "易订货-优惠券记录", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-优惠券记录")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhCouponLogService.deleteEdhCouponLogByIds(ids));
    }
}
